﻿using System;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;

using Telerik.WebControls;
using UFSoft.UBF.UI.WebControls;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.Util.Log;
using UFSoft.UBF.Util.Globalization;

using UFSoft.UBF.UI.IView;
using UFSoft.UBF.UI.Engine;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using UFIDA.U9.UI.PDHelper;
using UFSoft.UBF.UI.FormProcess;
using UFSoft.UBF.UI.WebControls.Association.Adapter;
using UFIDA.U9.Base.Doc;
using UFSoft.UBF.UI.WebControls.Association;



/***********************************************************************************************
 * Form ID: 
 * UIFactory Auto Generator 
 ***********************************************************************************************/
namespace UFIDA.U9.Cust.U9Demo.DeliverUI
{
    public partial class DocTypeUIFormWebPart
    {
        #region Custome eventBind
	
		 
				//BtnSave_Click...
		private void BtnSave_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnSave_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnCancel_Click...
		private void BtnCancel_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnCancel_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnAdd_Click...
		private void BtnAdd_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnAdd_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnDelete_Click...
		private void BtnDelete_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnDelete_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnCopy_Click...
		private void BtnCopy_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.

            if (this.Model.DocType.FocusedRecord != null)
                this.Model.DocType.FocusedRecord.Code = "";
            BtnCopy_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFind_Click...
		private void BtnFind_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFind_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnSubmit_Click...
		private void BtnSubmit_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnSubmit_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnApprove_Click...
		private void BtnApprove_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnApprove_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnList_Click...
		private void BtnList_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnList_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFirstPage_Click...
		private void BtnFirstPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFirstPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnPrevPage_Click...
		private void BtnPrevPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnPrevPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnNextPage_Click...
		private void BtnNextPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnNextPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnLastPage_Click...
		private void BtnLastPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnLastPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnAttachment_Click...
		private void BtnAttachment_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnAttachment_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFlow_Click...
		private void BtnFlow_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFlow_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnOutput_Click...
		private void BtnOutput_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnOutput_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnPrint_Click...
		private void BtnPrint_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnPrint_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnOk_Click...
		private void BtnOk_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnOk_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnClose_Click...
		private void BtnClose_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnClose_Click_DefaultImpl(sender,e);
		}

		
            
            
            

		#region 自定义数据初始化加载和数据收集
		private void OnLoadData_Extend(object sender)
		{
            //如果UIModel中没有定义按照组织过滤，可以在代码里面加上这个过滤
            //this.Model.DocType.CurrentFilter.OPath = this.Model.DocType.CurrentFilter.OPath + " Org=" + UI.PDHelper.PDContext.Current.OrgID;
            OnLoadData_DefaultImpl(sender);
		}
		private void OnDataCollect_Extend(object sender)
		{	
			OnDataCollect_DefaultImpl(sender);
		}
		#endregion  

        #region 自己扩展 Extended Event handler 
		public void AfterOnLoad()
		{

		}

        public void AfterCreateChildControls()
        {

            //开启个性化
            UFIDA.U9.UI.PDHelper.PersonalizationHelper.SetPersonalizationEnable((BaseWebForm)this, true);

            //查询按钮设置
            PDFormMessage.ShowConfirmDialog(this.Page, "b680aba7-cf8e-4999-bd00-119097de13d7", "580", "408",
                Title, wpFindID.ClientID, this.BtnFind, null);//FromID为单据类型的参照，可以从单据类型参照的第一个.cs文件的开头找到


            //取得提示信息资源：是否删除当前记录
            string message = PDResource.GetDeleteConfirmInfo();
            //绑定注册弹出对话框到删除按钮
            PDFormMessage.ShowConfirmDialog(this.Page, message, "", this.BtnDelete);
            PDFormMessage.ShowConfirmDialog(this.Page, "确认放弃当前记录？", "", this.BtnCancel);

            DocHeaderSequenceStyle_CallBack();
            ConfirmType_CallBack();

           

        }
        
        public void AfterEventBind()
        {
        }
        
		public void BeforeUIModelBinding()
		{

		}

		public void AfterUIModelBinding()
		{
            if (this.Model.DocType.FocusedRecord != null)
            {
                int seq = this.Model.DocType.FocusedRecord.DocHeaderSequenceStyle;
                ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocHeaderSequence94).ReadOnly = (seq != (int)DocHeaderSequenceStyleEnumData.Auto);

                int cfmType = this.Model.DocType.FocusedRecord.ConfirmType;
                ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.ApproveType113).ReadOnly = (cfmType != (int)ConfirmTypeEnumData.ApproveFlow);
            }
            else
            {
                ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocHeaderSequence94).ReadOnly = true;
                ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.ApproveType113).ReadOnly = true;
            }

            //如果页面是通过TitleLink进入则显示确定取消按钮
            if (NavigateManager.IsTitleLink(this))
            {
                this.BtnOk.Visible = true;
                this.BtnClose.Visible = true;

                BtnList.Enabled = false;
            }
            else if (NavigateManager.IsModelPopup(this))
            {
                this.BtnOk.Visible = false;
                this.BtnClose.Visible = false;

                BtnList.Enabled = false;
            }
            else
            {
                this.BtnOk.Visible = false;
                this.BtnClose.Visible = false;

                BtnList.Enabled = true;
            }

        }

        #region Customer Extend Method

        #region CallBack


        private void DocHeaderSequenceStyle_CallBack()
        {
            AssociationControl assoC = new AssociationControl();
            assoC.SourceServerControl = this.DocHeaderSequenceStyle115;
            assoC.SourceControl.EventName = "OnValueChanged";

            ClientCallBackFrm cF1 = new ClientCallBackFrm();
            cF1.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(DocHeaderSequenceStyle_CallBack_ContentChanged);
            cF1.ParameterControls.Add(this.DocHeaderSequenceStyle115);

            cF1.Add(assoC);
            this.Controls.Add(cF1);
        }

        private object DocHeaderSequenceStyle_CallBack_ContentChanged(CustomerActionEventArgs args)
        {
            int seq = GetEnumIntFromObj(args.ArgsHash[this.DocHeaderSequenceStyle115.ClientID]);

            if (this.Model.DocType.FocusedRecord != null)
            {
                this.Model.DocType.FocusedRecord.DocHeaderSequenceStyle = seq;
                this.Model.DocType.FocusedRecord.DocHeaderSequence = null;
                this.Model.DocType.FocusedRecord.DocHeaderSequence_Code = string.Empty;
                this.Model.DocType.FocusedRecord.DocHeaderSequence_Name = string.Empty;
            }

            ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocHeaderSequence94).ReadOnly = (seq != (int)DocHeaderSequenceStyleEnumData.Auto);

            UFWebClientRefControlAdapter seqAdapter = new UFWebClientRefControlAdapter(this.DocHeaderSequence94);
            seqAdapter.Enabled = (seq != (int)DocHeaderSequenceStyleEnumData.Auto)
                ? EnumClientAssoControlEnable.EnableFalse : EnumClientAssoControlEnable.EnableTrue;
            seqAdapter.Key = string.Empty;
            seqAdapter.Value = string.Empty;
            seqAdapter.Text = string.Empty;

            args.ArgsResult.Add(seqAdapter.ClientInstanceWithDataValue);
            args.ArgsResult.Add(seqAdapter.ClientInstanceWithEnable);

            return args;
        }


        private void ConfirmType_CallBack()
        {
            AssociationControl assoC = new AssociationControl();
            assoC.SourceServerControl = this.ConfirmType160;
            assoC.SourceControl.EventName = "OnValueChanged";

            ClientCallBackFrm cF1 = new ClientCallBackFrm();
            cF1.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(ConfirmType_CallBack_ContentChanged);
            cF1.ParameterControls.Add(this.ConfirmType160);

            cF1.Add(assoC);
            this.Controls.Add(cF1);
        }

        private object ConfirmType_CallBack_ContentChanged(CustomerActionEventArgs args)
        {
            int cfmType = GetEnumIntFromObj(args.ArgsHash[this.ConfirmType160.ClientID]);

            if (this.Model.DocType.FocusedRecord != null)
            {
                this.Model.DocType.FocusedRecord.ConfirmType = cfmType;
                this.Model.DocType.FocusedRecord.ApproveType = null;
            }
            ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.ApproveType113).ReadOnly = (cfmType != (int)ConfirmTypeEnumData.ApproveFlow);

            UFWebClientDropDownListAdapter seqAdapter = new UFWebClientDropDownListAdapter(this.ApproveType113);
            seqAdapter.Enabled = (cfmType != (int)ConfirmTypeEnumData.ApproveFlow)
                ? EnumClientAssoControlEnable.EnableFalse : EnumClientAssoControlEnable.EnableTrue;
            seqAdapter.Value = string.Empty;
            seqAdapter.Key = string.Empty;
            seqAdapter.Text = string.Empty;

            args.ArgsResult.Add(seqAdapter.ClientInstanceWithValue);
            args.ArgsResult.Add(seqAdapter.ClientInstanceWithEnable);

            return args;
        }


       
        #endregion

        #region Common Method

        private int GetEnumIntFromObj(object p)
        {
            int i = -1;
            if (p != null && p.ToString() != string.Empty)
            {
                if (int.TryParse(p.ToString(), out i))
                {
                    return i;
                }
            }

            return i;
        }

        #endregion

        #endregion

        #endregion

        #endregion

    }
}